<?php

class Section
{
	private $sectionNumber = -1;
	private $possibilities = array();
	private $complete = false;
	private $startingCellNumber = -1;
	private $row1_cells = array();
	private $row2_cells = array();
	private $row3_cells = array();
	private $col1_cells = array();
	private $col2_cells = array();
	private $col3_cells = array();
	
	public function __construct($options)
	{
		$this->sectionNumber = $options['section'];
		$this->startingCellNumber = $options['startingCell'];
		$this->row1_cells = $options['row1_cells'];
		$this->row2_cells = $options['row2_cells'];
		$this->row3_cells = $options['row3_cells'];	
		
		$this->col1_cells = $options['col1_cells'];
		$this->col2_cells = $options['col2_cells'];
		$this->col3_cells = $options['col3_cells'];		
		$this->initializeSection();
	}
	
	public function initializeSection()
	{
		$this->possibilities = $this->setupPossibilities();
	}
	
	public function setupPossibilities()
	{
		$tmp_poss = array();
		for($count =1; $count < Cell::MAX_VALUE; $count++)
		{
			$tmp_poss[] = $count;	
		}
		return $tmp_poss;
	}	
	
	public function getPossibilities()
	{
		return $this->possibilities;
	}
	
	public function isComplete()
	{
		return $this->complete;
	}
	
	public function setComplete()
	{
		$this->complete = True;
		$this->possibilities = array();
	}
	
	public function getSectionNumber()
	{
		return $this->sectionNumber;
	}
	
	public function getStartingCellNumber()
	{
		return $this->startingCellNumber;
	}
	
	public function removeFromPossibilities($value)
	{
		if(in_array($value, $this->possibilities))
		{
			$result = array_search($value, $this->possibilities);
			$possible_value = $this->possibilities;
			unset($possible_value[$result]);			
			$this->possibilities = array_values($possible_value);
		}
		
		if(count($this->possibilities) ==0 || $this->possibilities == NULL)
		{
			$this->setComplete();
		}
	}
	
	public function isPossible($value)
	{
		return in_array($value, $this->possibilities);
	}
	
	public function getRowNumbers($row_number)
	{
		$cells = "row".$row_number."_cells";
		return $this->$cells;
	}
	
	public function getColumnNumbers($col_number)
	{
		$cells = "col".$col_number."_cells";
		return $this->$cells;
	}
	
	public function cellInRow($cell_number, $row_number)
	{
		$cells = "row".$row_number."_cells";
		return in_array($cell_number, $this->$cells);
	}
	
	public function cellInColumn($cell_number, $col_number)
	{
		$cells = "col".$col_number."_cells";
		return in_array($cell_number, $this->$cells);
	}
	
}